T
A generic System.Type parameter.
LEADTOOLS (Leadtools assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
RasterCollection<T> Class
See Also  Members  
Leadtools Namespace : RasterCollection<T> Class



Represents a generic collection of objects. Supported in Silverlight, Windows Phone 7

Object Model

RasterCollection<T> ClassT Class

Syntax

Visual Basic (Declaration) 
<DefaultMemberAttribute("Item")>
<SerializableAttribute()>
Public Class RasterCollection(Of T) 
   Implements ICollection(Of T)IEnumerable(Of T)IList(Of T)IEnumerable 
Visual Basic (Usage)Copy Code
Dim instance As RasterCollection(Of T)
C# 
[DefaultMemberAttribute("Item")]
[SerializableAttribute()]
public class RasterCollection<T> : ICollection<T>IEnumerable<T>IList<T>IEnumerable  
C++/CLI 
[DefaultMemberAttribute("Item")]
[SerializableAttribute()]
generic<typename T>
public ref class RasterCollection : public ICollection<T>IEnumerable<T>IList<T>IEnumerable  

Type Parameters

T
A generic System.Type parameter.

Example

Sample to test the RasterCollection class.

Visual BasicCopy Code
Public Sub RasterCollectionExample()
   Dim rc As RasterCollection(Of String) = New RasterCollection(Of String)()
   AddHandler rc.ItemAdded, AddressOf rasterCollection_ItemAdded
   AddHandler rc.ItemRemoved, AddressOf rasterCollection_ItemRemoved

   ' add a few items
   Dim item1 As String = "item 1"
   Dim item2 As String = "item 2"
   Dim item3 As String = "item 3"

   rc.Add(item1)
   rc.Add(item2)
   rc.Add(item3)

   ' insert an item
   Dim newItem2 As String = "new item 2"
   rc.Insert(1, newItem2)

   ' check if collection contains this new item
   Debug.Assert(rc.Contains(newItem2))

   ' remove this new item
   rc.Remove(newItem2)
   Debug.Assert((Not rc.Contains(newItem2)))

   ' remove the last item
   rc.RemoveAt(rc.Count - 1)
   Debug.Assert(rc.Count = 2)

   ' send the first item to the end of the collection
   rc.SendToBack(item1, True)
   Debug.Assert(rc.IndexOf(item1) = rc.Count - 1)

   ' bring it back to the front
   rc.BringToFront(item1, True)
   Debug.Assert(rc.IndexOf(item1) = 0)

   ' copy to an array
   Dim items As String() = New String(rc.Count - 1) {}
   rc.CopyTo(items, 0)
   Debug.Assert(items.Length = rc.Count)
   Dim i As Integer = 0
   Do While i < items.Length
      Debug.Assert(items(i) = rc(i))
      i += 1
   Loop

   ' loop throw the items and show them
   For Each str As String In rc
      Console.WriteLine(str)
   Next str

   ' clean the collection
   rc.Clear()
   Debug.Assert(rc.Count = 0)
End Sub

Private Sub rasterCollection_ItemAdded(ByVal sender As System.Object, ByVal e As RasterCollectionEventArgs(Of String))
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been added to the collection")
End Sub

Private Sub rasterCollection_ItemRemoved(ByVal sender As System.Object, ByVal e As RasterCollectionEventArgs(Of String))
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been removed from the collection")
End Sub
C#Copy Code
public void RasterCollectionExample()
{
   RasterCollection<string> rc = new RasterCollection<string>();
   rc.ItemAdded += new EventHandler<RasterCollectionEventArgs<string>>(rasterCollection_ItemAdded);
   rc.ItemRemoved += new EventHandler<RasterCollectionEventArgs<string>>(rasterCollection_ItemRemoved);

   // add a few items
   string item1 = "item 1";
   string item2 = "item 2";
   string item3 = "item 3";

   rc.Add(item1);
   rc.Add(item2);
   rc.Add(item3);

   // insert an item
   string newItem2 = "new item 2";
   rc.Insert(1, newItem2);

   // check if collection contains this new item
   Debug.Assert(rc.Contains(newItem2));

   // remove this new item
   rc.Remove(newItem2);
   Debug.Assert(!rc.Contains(newItem2));

   // remove the last item
   rc.RemoveAt(rc.Count - 1);
   Debug.Assert(rc.Count == 2);

   // send the first item to the end of the collection
   rc.SendToBack(item1, true);
   Debug.Assert(rc.IndexOf(item1) == rc.Count - 1);

   // bring it back to the front
   rc.BringToFront(item1, true);
   Debug.Assert(rc.IndexOf(item1) == 0);

   // copy to an array
   string[] items = new string[rc.Count];
   rc.CopyTo(items, 0);
   Debug.Assert(items.Length == rc.Count);
   for(int i = 0; i < items.Length; i++)
      Debug.Assert(items[i] == rc[i]);

   // loop throw the items and show them
   foreach(string str in rc)
      Console.WriteLine(str);

   // clean the collection
   rc.Clear();
   Debug.Assert(rc.Count == 0);
}

private void rasterCollection_ItemAdded(System.Object sender, RasterCollectionEventArgs<string> e)
{
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been added to the collection");
}

private void rasterCollection_ItemRemoved(System.Object sender, RasterCollectionEventArgs<string> e)
{
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been removed from the collection");
}
SilverlightCSharpCopy Code
public void RasterCollectionExample()
{
   RasterCollection<string> rc = new RasterCollection<string>();
   rc.ItemAdded += new EventHandler<RasterCollectionEventArgs<string>>(rasterCollection_ItemAdded);
   rc.ItemRemoved += new EventHandler<RasterCollectionEventArgs<string>>(rasterCollection_ItemRemoved);
   // add a few items
   string item1 = "item 1";
   string item2 = "item 2";
   string item3 = "item 3";

   rc.Add(item1);
   rc.Add(item2);
   rc.Add(item3);

   // insert an item
   string newItem2 = "new item 2";
   rc.Insert(1, newItem2);

   // check if collection contains this new item
   Debug.Assert(rc.Contains(newItem2));

   // remove this new item
   rc.Remove(newItem2);
   Debug.Assert(!rc.Contains(newItem2));

   // remove the last item
   rc.RemoveAt(rc.Count - 1);
   Debug.Assert(rc.Count == 2);

   // send the first item to the end of the collection
   rc.SendToBack(item1, true);
   Debug.Assert(rc.IndexOf(item1) == rc.Count - 1);

   // bring it back to the front
   rc.BringToFront(item1, true);
   Debug.Assert(rc.IndexOf(item1) == 0);

   // copy to an array
   string[] items = new string[rc.Count];
   rc.CopyTo(items, 0);
   Debug.Assert(items.Length == rc.Count);
   for(int i = 0; i < items.Length; i++)
      Debug.Assert(items[i] == rc[i]);

   // loop throw the items and show them
   foreach(string str in rc)
      Console.WriteLine(str);

   // clean the collection
   rc.Clear();
   Debug.Assert(rc.Count == 0);
}

private void rasterCollection_ItemAdded(System.Object sender, RasterCollectionEventArgs<string> e)
{
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been added to the collection");
}

private void rasterCollection_ItemRemoved(System.Object sender, RasterCollectionEventArgs<string> e)
{
   Console.WriteLine("The Item ((" + e.Item.ToString() + ")) Has been removed from the collection");
}
SilverlightVBCopy Code
Public Sub RasterCollectionExample()
   Dim rc As RasterCollection(Of String) = New RasterCollection(Of String)()
   AddHandler rc.ItemAdded, AddressOf rasterCollection_ItemAdded
   AddHandler rc.ItemRemoved, AddressOf rasterCollection_ItemRemoved
   ' add a few items
   Dim item1 As String = "item 1"
   Dim item2 As String = "item 2"
   Dim item3 As String = "item 3"

   rc.Add(item1)
   rc.Add(item2)
   rc.Add(item3)

   ' insert an item
   Dim newItem2 As String = "new item 2"
   rc.Insert(1, newItem2)

   ' check if collection contains this new item
   Debug.Assert(rc.Contains(newItem2))

   ' remove this new item
   rc.Remove(newItem2)
   Debug.Assert((Not rc.Contains(newItem2)))

   ' remove the last item
   rc.RemoveAt(rc.Count - 1)
   Debug.Assert(rc.Count = 2)

   ' send the first item to the end of the collection
   rc.SendToBack(item1, True)
   Debug.Assert(rc.IndexOf(item1) = rc.Count - 1)

   ' bring it back to the front
   rc.BringToFront(item1, True)
   Debug.Assert(rc.IndexOf(item1) = 0)

   ' copy to an array
   Dim items As String() = New String(rc.Count - 1){}
   rc.CopyTo(items, 0)
   Debug.Assert(items.Length = rc.Count)
   Dim i As Integer = 0
   Do While i < items.Length
      Debug.Assert(items(i) = rc(i))
      i += 1
   Loop

   ' loop throw the items and show them
   For Each str As String In rc
      Console.WriteLine(str)
   Next str

   ' clean the collection
   rc.Clear()
   Debug.Assert(rc.Count = 0)
End Sub

Private Sub rasterCollection_ItemAdded(ByVal sender As System.Object, ByVal e As RasterCollectionEventArgs(Of String))
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been added to the collection")
End Sub

Private Sub rasterCollection_ItemRemoved(ByVal sender As System.Object, ByVal e As RasterCollectionEventArgs(Of String))
   Console.WriteLine("The Item ((" & e.Item.ToString() & ")) Has been removed from the collection")
End Sub

Remarks

The RasterCollection<T> class provides a generic collection class that implements the .NET IList, ICollection and IEnumerable interfaces.

The class contains the ItemAdded and ItemRemoved events. These events will fire whenever objects are added or removed to/from the collection.

Inheritance Hierarchy

System.Object
   Leadtools.RasterCollection<T>

Requirements

Target Platforms: Silverlight, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only), Windows Phone 7

See Also